package api

import (
	"GopherFocus/app/system/index/internal/define"
	"GopherFocus/app/system/index/internal/service"
	"GopherFocus/library/response"
	"github.com/gogf/gf/net/ghttp"
)

var Category = categoryApi{}

type categoryApi struct{}

// 获取栏目数
func (a *categoryApi) Tree(r *ghttp.Request) {
	var (
		req *define.CategoryGetTreeReq
	)
	if err := r.Parse(&req); err != nil {
		response.JsonExit(r, 1, err.Error())
	}
	// 返回所有类型为contentType且父节点id为0的所有节点构成的子树列表
	if tree, err := service.Category.GetTree(r.Context(), req.ContentType); err != nil {
		response.JsonExit(r, 1, err.Error())
	} else {
		response.JsonExit(r, 0, "", tree)
	}
}
